package com.ych.modules.api.authorInfc.user.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.ych.modules.base.dbEntity.TUserCardEntity;
import com.ych.modules.common.entity.query.QueryUserCardEntity;
import com.ych.modules.common.service.UserCardService;
import com.ych.utils.TLMap;
import com.ych.utils.mysqlPageUtil.PageUtils;
import com.ych.utils.serviceReturn.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created with IntelliJ IDEA.
 * Author: Usopp.tsui
 * Date: 2021/3/20
 * Time: 16:18
 * Description:
 */
@RestController("apiUserCardController")
@RequestMapping("/api/auth/user/card")
@Api(tags = {"用户卡信息相关"})
public class UserCardController {
    @Autowired
    private UserCardService userCardService;

    @PostMapping("/createUserCard")
    @ApiOperation(value = "创建用户卡", notes = "创建用户卡")
    public R<String> createUserCard(@RequestBody TUserCardEntity entity) {
        try {
            userCardService.createUserCard(entity);
            return new R(0, "成功", null);
        } catch (Exception e) {
            return new R(1, e.getMessage(), null);
        }
    }

    @PostMapping("/listUserCard")
    @ApiOperation(value = "查询卡信息列表", notes = "查询卡信息列表")
    public R<Page<TUserCardEntity>> listUserCard(@RequestBody QueryUserCardEntity entity) {
        try {
            entity.setUserId(TLMap.getUserId());
            Page<TUserCardEntity> page = userCardService.listUserCard(entity);
            return new R(0, "成功", new PageUtils(page));
        } catch (Exception e) {
            return new R(1, e.getMessage(), null);
        }
    }

    @PostMapping("/getUserCard")
    @ApiOperation(value = "查询卡信息", notes = "查询卡信息")
    public R<TUserCardEntity> getUserCard(@RequestBody String cardId) {
        try {
            TUserCardEntity cardEntity = userCardService.getUserCard(cardId);
            return new R(0, "成功", cardEntity);
        } catch (Exception e) {
            return new R(1, e.getMessage(), null);
        }
    }
}
